package com.korubo.web.contrller;

import cn.hutool.core.lang.UUID;
import com.korubo.kit.R;
import com.korubo.web.model.Role;
import com.korubo.web.model.RoleMenu;
import com.korubo.web.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (tb_role)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    /**
     * 服务对象
     */
    @Resource
    private RoleService roleService;

    @PostMapping("list")
    public R list(@RequestBody(required = false) Role role) {
        return roleService.list(role);
    }

    @PostMapping("add")
    public R add(@RequestBody Role role) {
        role.setId(UUID.fastUUID().toString());
        return roleService.save(role) ? R.ok() : R.fail();
    }

    @PostMapping("update")
    public R update(@RequestBody Role role) {
        return roleService.
                updateById(role) ? R.ok() : R.fail();
    }

    @PostMapping("delete")
    public R delete(@RequestBody Role role) {
        return roleService.removeById(role) ? R.ok() : R.fail();
    }

    @PostMapping("findById")
    public R findById(@RequestBody Role role) {
        return R.ok().data(roleService.getById(role.getId()));
    }

    //保存角色和菜单的关联
    @PostMapping("saveRoleMenu")
    public R saveRoleMenu(@RequestBody Role role) {
        return roleService.saveRoleMenu(role);
    }

    @PostMapping("getRoleMenu")
    public R getRoleMenu(@RequestBody Role role) {
        return roleService.getRoleMenu(role);
    }

}
